package minio.web.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 文件分片信息表，仅在手动分片上传时使用
 * @author ljl
 * @TableName file_part_detail
 */
@TableName(value ="file_part_detail")
@Data
public class FilePartDetail implements Serializable {
    public static final String COL_UPLOAD_ID = "upload_id";
    /**
     * 分片id
     */
    @TableId
    private String id;

    /**
     * 存储平台
     */
    private String platform;

    /**
     * 上传ID，仅在手动分片上传时使用
     */
    private String uploadId;

    /**
     * 分片 ETag
     */
    private String eTag;

    /**
     * 分片号。每一个上传的分片都有一个分片号，一般情况下取值范围是1~10000
     */
    private Integer partNumber;

    /**
     * 文件大小，单位字节
     */
    private Long partSize;

    /**
     * 哈希信息
     */
    private String hashInfo;

    /**
     * 创建时间
     */
    private Date createTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        FilePartDetail other = (FilePartDetail) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getPlatform() == null ? other.getPlatform() == null : this.getPlatform().equals(other.getPlatform()))
            && (this.getUploadId() == null ? other.getUploadId() == null : this.getUploadId().equals(other.getUploadId()))
            && (this.getETag() == null ? other.getETag() == null : this.getETag().equals(other.getETag()))
            && (this.getPartNumber() == null ? other.getPartNumber() == null : this.getPartNumber().equals(other.getPartNumber()))
            && (this.getPartSize() == null ? other.getPartSize() == null : this.getPartSize().equals(other.getPartSize()))
            && (this.getHashInfo() == null ? other.getHashInfo() == null : this.getHashInfo().equals(other.getHashInfo()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getPlatform() == null) ? 0 : getPlatform().hashCode());
        result = prime * result + ((getUploadId() == null) ? 0 : getUploadId().hashCode());
        result = prime * result + ((getETag() == null) ? 0 : getETag().hashCode());
        result = prime * result + ((getPartNumber() == null) ? 0 : getPartNumber().hashCode());
        result = prime * result + ((getPartSize() == null) ? 0 : getPartSize().hashCode());
        result = prime * result + ((getHashInfo() == null) ? 0 : getHashInfo().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", platform=").append(platform);
        sb.append(", uploadId=").append(uploadId);
        sb.append(", eTag=").append(eTag);
        sb.append(", partNumber=").append(partNumber);
        sb.append(", partSize=").append(partSize);
        sb.append(", hashInfo=").append(hashInfo);
        sb.append(", createTime=").append(createTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}